#/*
# * Copyright {c} 2020-2021, SERI Development Team
# *
# * SPDX-License-Identifier: Apache-2.0
# *
# * Change Logs:
# * Date         Author          Notes
# * 2023-06-24   Lyons           first version
# */

ifeq ($(shell uname), Linux)
TARGET = ./xemu
CC     = gcc
PARAM  = -std=gnu99
LIB    = -lcurses -lpthread -lm
else
TARGET = .\xemu.exe
CC     = D:\MinGW\bin\gcc.exe
PARAM  = 
LIB    = -lpthread -lm
endif

BINFILE = ./riscv.bin

CFILE   = ./xemu.c

PARAM  += -DENABLE_TIMER -DENABLE_UART -DENABLE_GPIO

.PHONY: build
build:
	@${CC} ${PARAM} ${CFILE} ${LIB} -o ${TARGET}

.PHONY: run
run:
ifeq ($(shell uname), Linux)
	@if [ -e ${BINFILE} ]; then echo; ${TARGET} ${BINFILE}; else echo "${BINFILE} missing!"; fi
else
	@${TARGET} ${BINFILE}
endif

.PHONY: clean
clean:
	@rm -rf ${TARGET} *.log
	@rm -rf *.bin
